package com.jinyu.jyly.ui.mine.order.detail;

import android.app.Activity;

import com.jinyu.jyly.base.BasePresenter;
import com.jinyu.jyly.bean.AllInfoBean;
import com.jinyu.jyly.net.DataManager;

import java.util.List;

import okhttp3.MultipartBody;
import rx.Subscription;
import rx.functions.Action1;

public class OrderDetailPresenter extends BasePresenter<OrderDetailContract.View> implements OrderDetailContract.Presenter {

    public OrderDetailPresenter(Activity activity, OrderDetailContract.View view) {
        super(activity, view);

    }


    /**
     * 我的订单
     * @param param
     */
    @Override
    public void getorderPayment(String param) {
        Subscription subscribe = DataManager.getInstance().getOrderPayment(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onGetOrderPayment(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }


    /**
     * 更新订单状态
     * @param param
     */
    @Override
    public void getChangeOrder(String param) {
        Subscription subscribe = DataManager.getInstance().getChangeOrder(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onChangeOrder(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }



    @Override
    public void updataImg(List<MultipartBody.Part> body) {
        Subscription subscribe = DataManager.getInstance().updataImg(body)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onUpdataImg(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }



}
